package com.miyake.dsp.converter;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;
import com.miyake.dsp.ScilabExecute;

public class WindowScilab implements Processor {

	private ComplexArray source;
	private WindowSetting setting;

	public WindowScilab(WindowSetting setting) {
		this.setting = setting;
	}
	
	@Override
	public void setSource(ComplexArray source) {
		this.source = source;
	}

	@Override
	public ComplexArray getSource() {
		return this.source;
	}

	@Override
	public ComplexArray getProcessed() {
		String type = null;
		if (setting.getWindow().equals(WindowSetting.HAMMING)) {
			type = "hm";
		}
		else if (setting.getWindow().equals(WindowSetting.HANNING)) {
			type = "hn";
		}
		else if (setting.getWindow().equals(WindowSetting.TRIANGLE)) {
			type = "tr";
		}
		String cmd = "w=window('" + type + "'," +source.getRealPart().length +  ");ret=data1. * w;";
		return ScilabExecute.execute(cmd, source, "ret");
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
